package com.mpyy.handler.systemSetting;

import com.alibaba.fastjson.JSON;
import com.mpyy.dao.ToolInter;
import com.mpyy.dao.ToolsInter;
import com.mpyy.pojo.MenmberInfo;
import com.mpyy.pojo.MenmberTypeld;
import com.mpyy.pojo.SaleOrder;
import com.mpyy.pojo.SaleOrderDesc;
import com.mpyy.service.systemSetting.ClientServiceInter;
import com.mpyy.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * @PackageName:com.mpyy.handler.systemSetting
 * @ClassName:ClientHandler
 * @Date:2022-03-25:11:15
 * @Author: Tang Neng
 */
@Controller
public class ClientHandler {
    @Autowired
    private ClientServiceInter clientServiceInter;
    /**封装了一个集合装JSON格式的方法*/
    public static String hashMapInfo(List objects){
        HashMap<Object, Object> hashMapInfo = new HashMap<>();
        //对JSON格式进行拼接
        hashMapInfo.put("code",0);
        hashMapInfo.put("msg","");
        hashMapInfo.put("count",objects.size());
        hashMapInfo.put("data",objects);
        return JSON.toJSONString(hashMapInfo);
    }


    /**添加会员信息*/
    @RequestMapping(value = "/updateClientInfoAdd" , method = RequestMethod.POST) @ResponseBody
    public int updateClientInfoAdd(MenmberInfo menmberInfo){
        menmberInfo.setMenStatus(null != (menmberInfo.getMenStatus()) ? "0" : "1");
        menmberInfo.setMenPointUpgrade(null != (menmberInfo.getMenPointUpgrade()) ? "0" : "1");
        int i = clientServiceInter.updateMenmberInfoAdd(menmberInfo);
        return i;
    }

    /**获取会员等级输出到页面*/
    @RequestMapping(value = "/searchClientTypeInfo",produces = "application/json;charset=UTF-8") @ResponseBody
    public String searchClientTypeInfo(){
        List<MenmberTypeld> menmberTypelds = clientServiceInter.searchMenmberTypeInfo();
        //装换成JSON格式的字符串，返回到页面
        return hashMapInfo(menmberTypelds);
    }
    @Autowired
    private ToolsInter toolInter;

    /**获取会员id进行自增操作*/
    @RequestMapping(value = "/searchClientIdInfo", method = RequestMethod.GET) @ResponseBody
    public String searchClientIdInfo(String menId , String table){
        String id = new Tool().aotomaticId(menId , table, toolInter);
        return id;
    }

    /**搜索当前会员信息输出到页面*/
    @RequestMapping(value = "/searchClientInfo" , method = RequestMethod.GET , produces = "application/json;charset=UTF-8") @ResponseBody
    public String searchClientInfo(String menName){
        List<MenmberInfo> menmberInfos = clientServiceInter.searchMenmberInfo(menName);
        return hashMapInfo(menmberInfos);
    }
    /**根据会员编号查询该会员绑定了，哪些客户，在对客户消费订单进行查询*/
    @RequestMapping(value = "/serchClientSaleOrderDescInfo" , method = RequestMethod.GET , produces = "appliction/json;charset=UTF-8") @ResponseBody
    public String serchClientSaleOrderDescInfo(String menId){
        List<SaleOrder> saleOrderDescs = clientServiceInter.searchMenmberSaleOrderDescInfo(menId);
        return hashMapInfo(saleOrderDescs);
    }

    /**修改会员信息*/
    @RequestMapping(value = "/updateClientInfo" , method = RequestMethod.GET) @ResponseBody
    public int updateClientInfo(){
        return 0;
    }
}
